﻿using Commom;
using Common;
using EF_Brave.Domain.bll;
using EF_Brave.Domain.bll_i;
using EF_Brave.Model;
using EF_Brave.Service.Logging;
using EFBrave.SQLServer;
using FD.TradingCenter.Infrastructure.Logging;
using StackExchange.Profiling;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace EF_Brave.Web.Controllers
{
    public class DefaultController : Controller
    {
        //
        // GET: /Default1/
        public ActionResult Index()
        {
            string Name = "Gaojianchao";
            string sql = "SELECT * FROM SYS_USER";
            var profiler = MiniProfiler.Current;
            DataTable dt = new DataTable();
            //StopWatch sw = new StopWatch();
            using (profiler.Step("查询"))
            {
                dt = DBHelper.GetTable(sql);
            }
            string json = JsonConverter.ToJson(dt);
            //List<UserClass> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UserClass>>(json);
            List<UserClass> _list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UserClass>>(json);
            ViewBag.USERS = _list;
            ViewBag.Name = Name;
            var list = new UserManageBLL().GetAll();
            ViewBag.USERS2 = list;
            //LoggerBLL.GetLogger().Log(LogLevel.Debug, "已经进入首页");
            //LoggerBLL.GetLogger().Log(LogLevel.Information, "已经进入首页");
            //LoggerBLL.GetLogger().Log(LogLevel.Warning, "已经进入首页");
            //LoggerBLL.GetLogger().Log(LogLevel.Error, "进错页面了");
            //LoggerBLL.GetLogger().Log(LogLevel.Fatal, "进错页面了");
            //测试log记录

            //CreateData();//创建两万条数据
            return View();
        }



        /// <summary>
        /// 添加测试数据
        /// </summary>
        /// <returns></returns>
        private bool CreateData()
        {
            int count = 2000;
            List<Sys_User> list = new List<Sys_User>();
            for (int i = 0; i < count; i++)
            {
                Sys_User user = new Sys_User()
                {
                    UserName = "gjc" + i,
                    UserTrueName = "noway" + i,
                    PassWord = "123456",
                    CreateDate = DateTime.Now,
                    Code = "1000" + i,
                    PreIpAddress = ":1",
                    LastIpAddress = ":1",
                    LastDate = DateTime.Now.AddDays(-2),
                    Status = "0"
                };
                list.Add(user);
            }
            return DIContainer.Resolve<IUserManage>().SaveList(list, true);
        }






        public class UserClass
        {
            public int Id { get; set; }
            public string UserName { get; set; }

            public string UserTrueName { get; set; }
            public string PassWord { get; set; }

            public DateTime CreateDate { get; set; }

            public string Code { get; set; }

            public string PreIpAddress { get; set; }

            public DateTime LastDate { get; set; }

            public string Status { get; set; }

            // public virtual ICollection<Sys_Roles> Roles { get; set; }
        }
    }
}